﻿using System;
using System.Web;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foothill.Utils;
using Foothill.WF.Command;
using Foothill.WF.Core;
using GGFW.Entity.SystemManage;
using Foothill.Privilege;
using Foothill.Privilege.Entity;
using Foothill.Privilege.Utils;
using GGFW.BusinessLogic.SystemManage;

namespace GGFW.Command.SystemManage
{
    public class FoothillMenuCommand : DispatchCommand
    {
        /// <summary>
        /// 功能菜单
        /// </summary>
        /// <param name="context">Http的特定信息，包含查询条件</param>
        /// <param name="requestType">请求提交方式</param>
        /// <param name="url">预留参数，暂未使用</param>
        /// <returns>返回结果集</returns>
        public ResultBase onGetFunctions(HttpContext context, RequestType requestType, string url)
        {

            ResultBase result = null;
            try
            {
                System.Web.HttpContext hc = System.Web.HttpContext.Current;
                FoothillUser user = hc.Session[PublicConstants.SESSION_USER] as FoothillUser;

                using (FoothillMenuControl control = new FoothillMenuControl())
                {
                    result = control.GetFunctions((int)user.UserID);
                }
            }
            catch (Exception ex)
            {
                result = new ResultBase();
                result.Success = false;
                result.Message = ex.Message;
                // result.AddErrorDetail(-1, ex.Message);
                // log.Fatal(ex.Message);
            }
            return result;
        }

        /// <summary>
        /// 获取角色具有权限的功能菜单
        /// </summary>
        /// <param name="context">Http的特定信息，包含查询条件</param>
        /// <param name="requestType">请求提交方式</param>
        /// <param name="url">预留参数，暂未使用</param>
        /// <returns>返回结果集</returns>
        public ResultBase onGetFunctionsByRole(HttpContext context, RequestType requestType, string url)
        {

            ResultBase result = null;
            try
            {
                // 获取参数
                int RoleID = NumericUtil.toInteger(context.Request["RoleID"], 0);

                using (FoothillMenuControl control = new FoothillMenuControl())
                {
                    result = control.GetFoothillMenuByRoleID(RoleID);
                }
            }
            catch (Exception ex)
            {
                result = new ResultBase();
                result.Success = false;
                result.Message = ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 获取角色具有权限的功能菜单
        /// </summary>
        /// <param name="context">Http的特定信息，包含查询条件</param>
        /// <param name="requestType">请求提交方式</param>
        /// <param name="url">预留参数，暂未使用</param>
        /// <returns>返回结果集</returns>
        public ResultBase onGetFunctionsByUser(HttpContext context, RequestType requestType, string url)
        {

            ResultBase result = null;
            try
            {
                // 获取参数
                int UserID = NumericUtil.toInteger(context.Request["UserID"], 0);

                using (FoothillMenuControl control = new FoothillMenuControl())
                {
                    result = control.GetFoothillMenuByUserID(UserID);
                }
            }
            catch (Exception ex)
            {
                result = new ResultBase();
                result.Success = false;
                result.Message = ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 设置角色菜单
        /// </summary>
        /// <param name="context">HttpContext</param>
        /// <param name="requestType">RequestType</param>
        /// <param name="url">url</param>
        /// <returns></returns>
        public ResultBase onSetMenuRole(HttpContext context, RequestType requestType, string url)
        {
            //返回结果
            ResultBase result = null;
            try
            {
                // 获取参数
                string MenuIDs = context.Request["MenuIDs"];
                string RoleID = context.Request["RoleID"];
                // 方法
                FoothillMenuControl FoothillMenuControl = new FoothillMenuControl();
                result = FoothillMenuControl.SetMenuRole(MenuIDs, RoleID);
            }
            catch (Exception ex)
            {
                result = new ResultBase();
                result.Success = false;
                result.Message = ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 设置用户菜单
        /// </summary>
        /// <param name="context">HttpContext</param>
        /// <param name="requestType">RequestType</param>
        /// <param name="url">url</param>
        /// <returns></returns>
        public ResultBase onSetMenuUser(HttpContext context, RequestType requestType, string url)
        {
            //返回结果
            ResultBase result = null;
            try
            {
                // 获取参数
                string MenuIDs = context.Request["MenuIDs"];
                string UserID = context.Request["UserID"];
                // 方法
                FoothillMenuControl FoothillMenuControl = new FoothillMenuControl();
                result = FoothillMenuControl.SetMenuUser(MenuIDs, UserID);
            }
            catch (Exception ex)
            {
                result = new ResultBase();
                result.Success = false;
                result.Message = ex.Message;
            }
            return result;
        }
    }
}
